extends RichTextLabel

var delta_time = 0
export var speed = 0.02
export var step = 2
var speaking = false

func setText(v : String):
	self.text = v
	delta_time = 0
	visible_characters = 0
	speaking = v.length() != 0
	
func setSpeak(v : bool):
	speaking = v
	
func clearText():
	setText('')
	
func click():
	if text.length() == visible_characters:
		setSpeak(false)
	else:
		visible_characters = text.length()

func text_update():
	if(text.length() > visible_characters):
		visible_characters = visible_characters + step
		if visible_characters >= text.length():
			visible_characters = text.length()

func _process(delta):
	if(delta_time > speed):
		delta_time = 0
		text_update()
	delta_time = delta_time + delta
